package com.api.shopapi.mapper;

import com.api.shopapi.entity.ActivityItem;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface ActivityItemMapper {


    @Insert("insert into activity_item " +
            "(" +
            "ActivityItemCode," +
            "ActivityTypeCode," +
            "Name," +
            "Status," +
            "GovernmentCode," +
            "CommandCenterCode," +
            "CreateTime" +
            ") " +
            "values " +
            "(" +
            "#{activityItem.ActivityItemCode}," +
            "#{activityItem.ActivityTypeCode}," +
            "#{activityItem.Name}," +
            "#{activityItem.Status}," +
            "#{activityItem.GovernmentCode}," +
            "#{activityItem.CommandCenterCode}," +
            "#{activityItem.CreateTime}" +
            ")" )
    int insert(@Param("activityItem") ActivityItem activityItem);


    @Delete("delete from activity_item where activityItemCode=#{activityItemCode}")
    int delete(@Param("activityItemCode") String activityItemCode);


    @Update("update activity_item set " +
            " Name=#{activityItem.Name}," +
            " Status=#{activityItem.Status}," +
            " ActivityTypeCode=#{activityItem.ActivityTypeCode}" +
            " where ActivityItemCode=#{activityItem.ActivityItemCode}")
    int update(@Param("activityItem") ActivityItem activityItem);


    @Select("select * from activity_item where activityItemCode=#{activityItemCode} limit 1")
    ActivityItem getByActivityItemCode(@Param("activityItemCode") String activityItemCode);


    @Select("select * from activity_item where activityTypeCode=#{activityTypeCode}" +
            " order by CreateTime desc")
    List<ActivityItem> ListByActivityTypeCode(@Param("activityTypeCode") String activityTypeCode);


    @Select("<script>" +
            "select * from activity_item where commandCenterCode=#{commandCenterCode}" +
            "<if test =' activityTypeCode != \"\" '>" +
            " and activityTypeCode = #{activityTypeCode} " +
            "</if>" +
            " order by CreateTime desc" +
            "</script>")
    List<ActivityItem> listByCommandCenterCodeActivityTypeCode(@Param("commandCenterCode") String commandCenterCode,
                                                            @Param("activityTypeCode") String activityTypeCode);


}
